var e = getApp().globalData.api, o = getApp();

Page({
    data: {
        formObj: {
            encryptedData: "",
            iv: "", 
            sessionKey:wx.getStorageSync("sessionKey"),
            loginSource: o.globalData.appInfo.zkSource,
            zkPlat: o.globalData.appInfo.zkPlat
        },
        userInfo: {},
        hasUserInfo: !1,
        phone:''
    },
    onLoad: function(e) {
        console.log(22);
        // getOpenid  getOpenId
        o.getOpenId().then(function(e) {}, function(e) {
            console.log(3333);
            console.log(e);
        });
    },
    getPhoneNumber: function(e) {
        console.log(e);
        var t = this;
        "getPhoneNumber:fail user deny" != e.detail.errMsg && "getPhoneNumber:fail:user deny" != e.detail.errMsg ? (this.setData({
            "formObj.encryptedData": e.detail.encryptedData,
            "formObj.iv": e.detail.iv
        }), wx.checkSession({
            success: function(e) {
                console.log(e), t.wxLogin();
            },
            fail: function(e) {
                console.log(e), o.getOpenId().then(function(o) {
                    o.code > 0 ? t.wxLogin() : (wx.showToast({
                        title: o.msg,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    }), console.log(e));
                }, function(e) {
                    console.log(e);
                });
            }
        })) : wx.showModal({
            title: "未获取手机号",
            content: "未登录，无法获取完整信息",
            showCancel: !0,
            cancelText: "取消",
            cancelColor: "#000000",
            confirmText: "我知道了",
            confirmColor: "#45AA30",
            success: function(e) {}
        });
    },
    wxLogin: function() {
        console.log("wxlogin")
        let that=this;
        // 
        var t = "", n = "";
        var a = 99999;//  wx.getStorageSync("disCode")
        // a = a || getApp().globalData.keyTjgj.disCode;
        try {
            t = wx.getStorageSync("openId"), 
            n = wx.getStorageSync("unionId"),
            // formObj
             this.setData({
                "formObj.authThirdToken": t,
                "formObj.authThirdUnionToken": n
            });
        } catch (e) {
            console.log("youwu");
        }
        console.log(this.data.formObj);
        //  
        e.post1("wechat/Apiwechat/wxtel", this.data.formObj).then(function(e) {
 
            if ("1" == e.code) {
                wx.setStorageSync("phoneNumber", e.data.phoneNumber);
                that.setData({phone:e.data.phoneNumber});  
                console.log(e.data.phoneNumber);
                that.onSubmitphone();
                // var o = getCurrentPages(), t = o[o.length - 2];
                // t && t.setData({
                //     loginType: !0
                // }), wx.setStorageSync("token", e.values.token);
                // var n = wx.getStorageSync("classify");
                // "1B10" == (n = n || getApp().globalData.keyTjgj.classify) && (getApp().globalData.token = "", 
                // getApp().globalData.keyTjgj.disCode = "", 
                // getApp().globalData.keyTjgj.classify = "", 
                // wx.removeStorageSync("disCode"), wx.removeStorageSync("classify"), 
                // wx.removeStorageSync("userId")), 
                // getApp().globalData.keyTjgj = {
                //     disCode: "",
                //     classify: ""
                // }, getApp().saveHosAndPkgHistory(), 
                wx.navigateBack({
                    delta: 1
                });
            }
        }, function(e) {
            wx.removeStorageSync("openId"), o.getOpenId(), wx.showToast({
                title: e.data.message[0].message,
                icon: "none",
                duration: 2e3,
                mask: !0
            }), console.log(e);
        });
    },

    onSubmitphone(){
        let that=this;  
        console.log("phonefanxie",that.data.phone)
        if(!that.data.phone){
          return wx.showToast({
            title: '请填写',
            icon: 'none'
          })
        }
        wx.showLoading();
       // 更新手机号
        e.post1("wechat/home/setMemberInfo", {
            mobile:that.data.phone,
            flag: 2,
            openid:wx.getStorageSync("openid")
        }).then(function(e) {

            if ("1" == e.code) {

                wx.hideLoading();
                // that.setData({show:false});
                wx.showToast({
                  title: '登录成功！',
                  icon: 'success'
                })
               // that.getUinfo(); 
            };


        })
        

      },

      getUinfo: function() {
        let that=this;  
        
        wx.showLoading({
            title: "正在加载中..."
        });
        var t = wx.getStorageSync('openid');
   
            e.post1("wechat/Member/getUserInfo", {
                openid: t
            }).then(function(fh) {
            if (wx.hideLoading(), "1" == fh.code) {
                var a = fh.data;
                console.log("uinfo",a)
                wx.setStorageSync('userinfo', fh.data);
                wx.setStorageSync('uid',fh.data.id);
                wx.setStorageSync('phoneNumber', fh.data.mobile);

                // let img=config.apiwimgURL+ t.data.headimgurl;
                // console.log(img);
                // e.setData({avatarUrl:s.apiwimgURL+ t.data.headimgurl}); 
                //   if( t.data.alias_nickname&& t.data.headimgurl){
                //     e.setData({avatarUrl:s.apiwimgURL+ t.data.headimgurl,needlogin:0,nickName1: t.data.alias_nickname,mobile:t.data.mobile}); 
                 
                //   }  
         
            } else {

                wx.showModal({
                    title: "提示",
                    content: "暂无数据",
                    showCancel: !1
                }); 
            };
        });
    },



    onShareAppMessage: function() {}
});